﻿using Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security.OAuth;
using System;

namespace OAuthServerApi.App_Start
{
    public partial class Startup
    {
        public void ConfigureAuth(IAppBuilder app)
        {
            var OauthSeverOptions = new OAuthAuthorizationServerOptions
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString(AppConstNum.AccessTokenUrl),
                Provider = new GrantPwdAuthorizationServerProvider(),
                AccessTokenExpireTimeSpan = TimeSpan.FromSeconds(AppConstNum.expires_in_second + 1),
                AuthorizeEndpointPath = new PathString(AppConstNum.AuthorzieUrl),
                AuthorizationCodeExpireTimeSpan = TimeSpan.FromSeconds(AppConstNum.expires_in_second + 1),
                AuthorizationCodeProvider = new CustomAuthorizeCodeProvider(),
                AccessTokenProvider = new CustomAccessTokenProvider(),
                RefreshTokenProvider = new CustomRefreshAccessTokenProvider(),
                ApplicationCanDisplayErrors = true,
            };
            app.UseOAuthAuthorizationServer(OauthSeverOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
        }
    }
}